import sys
import os
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
from PySide6.QtCore import QTimer, QObject, Signal
from time import strftime, localtime
# from getpath import getpath
# from alchemy import backend_alchemy
# from alchemy.obj_sqlalchemy import *
import json
class Backend(QObject):
    updated = Signal(str, arguments=['time'])
    def __init__(self):
        super().__init__()
        # Define timer.
        self.timer = QTimer()
        self.timer.setInterval(100)  # msecs 100 = 1/10th sec
        self.timer.timeout.connect(self.update_time)
        self.timer.start()
    def update_time(self):
        curr_time = strftime("%H:%M:%S", localtime())
        self.updated.emit(curr_time)
def getpath():
    return os.path.split(__file__)[0]
def main():
    app = QGuiApplication(sys.argv)
    file_path=getpath()
    engine = QQmlApplicationEngine()
    engine.quit.connect(app.quit)
    engine.load(os.path.join(file_path,'clock.qml'))


    # Define our backend object, which we pass to QML.
    backend = Backend()

    engine.rootObjects()[0].setProperty('backend', backend)

    # Initial call to trigger first update. Must be after the setProperty to connect signals.
    backend.update_time()

    sys.exit(app.exec())
main()